﻿using System;
using System.Web.Mvc;
using Mindfor.Web.Data;
using Mindfor.Web.Models;

namespace Mindfor.Web
{
	/// <summary>
	/// Represents the properties and methods that are needed in order to render a view that uses ASP.NET Razor syntax.
	/// Contains properties and fields to access WebMP features.
	/// </summary>
	public abstract class CmsRazorViewPage : WebViewPage
	{
		/// <summary>
		/// Gets current authenticated user. Returns null if user is anonymous or
		/// request context does not inherits <see cref="CmsController"/>.
		/// </summary>
		public new User User
		{
			get
			{
				CmsController c = this.ViewContext.Controller as CmsController;
				return c != null ? c.User : null;
			}
		}

		/// <summary>
		/// Gets page title from ViewData. If no page title exists then creates new one.
		/// </summary>
		public PageTitleCollection PageTitle
		{
			get
			{
				PageTitleCollection title = ViewData.GetPageTitle();
				if (title == null)
				{
					title = new PageTitleCollection();
					ViewData.SetPageTitle(title);
				}
				return title;
			}
		}
	}

	/// <summary>
	/// Represents the properties and methods that are needed in order to render a view that uses ASP.NET Razor syntax.
	/// Contains properties and fields to access WebMP features.
	/// </summary>
	public abstract class CmsRazorViewPage<TModel> : WebViewPage<TModel>
	{
		/// <summary>
		/// Gets current authenticated user. Returns null if user is anonymous or
		/// request context does not inherits <see cref="CmsController"/>.
		/// </summary>
		public new User User
		{
			get
			{
				CmsController c = this.ViewContext.Controller as CmsController;
				return c != null ? c.User : null;
			}
		}

		/// <summary>
		/// Gets page title from ViewData. If no page title exists then creates new one.
		/// </summary>
		public PageTitleCollection PageTitle
		{
			get
			{
				PageTitleCollection title = ViewData.GetPageTitle();
				if (title == null)
				{
					title = new PageTitleCollection();
					ViewData.SetPageTitle(title);
				}
				return title;
			}
		}
	}
}
